﻿using Hotel.BLL;
using Hotel.Model.Discount;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DiscountController : ControllerBase
    {

        DiscountBLL bll;

        public DiscountController( DiscountBLL bll) {
            this.bll = bll;
        }

        /// <summary>
        /// 增加优惠券
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult PostAddDiscount(T_Discount info)
        {
            try
            {
                int r = bll.PostAddDiscount(info);
               
                return Ok(new
                {
                    data = r,
                });
               

            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取优惠券类型列表
        /// </summary>
        /// <returns>返回符合条件的数据</returns>
        [HttpGet]
        public IActionResult GetDiscountTypeList()
        {
            try
            {
                List<T_Discount_Type> list = bll.GetDiscountTypeList();
                return Ok(new
                {
                    data = list,
                });
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 获取所有门店
        /// </summary>
        /// <param name="totalPage"></param>
        /// <param name="totalCount"></param>
        /// <param name="Ddid"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDiscountList( int? DTid = null, int pageIndex = 1, int pageSize = 2)
        {
            try
            {
                int totalPage = 0;
                int totalCount = 0;
                
               var list = bll.GetDiscountList(out totalPage, out totalCount, DTid, pageIndex, pageSize);

                return Ok(new
                {
                    data = list,
                    totalPage = totalPage,
                    totalCount = totalCount,
                });
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 查询所有使用过的优惠券
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDiscountUsed()
        {
            try
            {
                var list = bll.GetDiscountUsed();

                return Ok(new
                {
                    data = list
                });
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
